package com.mars.admin.modules.post.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mars.admin.framework.listener.EntityChangeListener;
import com.mybatisflex.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * 帖子浏览记录实体类
 *
 * @author Mars
 * @version 1.0
 * @date 2025-01-07
 */
@Data
@Accessors(chain = true)
@Table(value = "tb_post_view", onInsert = EntityChangeListener.class, onUpdate = EntityChangeListener.class)
@Schema(description = "帖子浏览记录")
public class PostView {

    private static final long serialVersionUID = 1L;

    /**
     * 浏览记录ID
     */
    @Id(keyType = KeyType.Auto)
    @Schema(description = "浏览记录ID", example = "1")
    private Long id;

    /**
     * 帖子ID
     */
    @Schema(description = "帖子ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
    @Column("post_id")
    private Long postId;

    /**
     * 用户ID
     */
    @Schema(description = "用户ID", example = "1")
    @Column("user_id")
    private Long userId;

    /**
     * 访客IP
     */
    @Schema(description = "访客IP", example = "192.168.1.1")
    @Column("visitor_ip")
    private String visitorIp;

    /**
     * 用户代理
     */
    @Schema(description = "用户代理", example = "Mozilla/5.0...")
    @Column("user_agent")
    private String userAgent;

    /**
     * 来源页面
     */
    @Schema(description = "来源页面", example = "https://example.com/page")
    @Column("referer")
    private String referer;

    /**
     * 浏览时长
     */
    @Schema(description = "浏览时长（秒）", example = "30")
    @Column("duration")
    private Integer duration;

    /**
     * 首次浏览时间
     */
    @Schema(description = "首次浏览时间", example = "2024-01-01 12:00:00")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(value = "create_time", onInsertValue = "now()")
    private LocalDateTime createTime;

    /**
     * 最后浏览时间
     */
    @Schema(description = "最后浏览时间", example = "2024-01-01 12:00:00")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(value = "update_time", onInsertValue = "now()", onUpdateValue = "now()")
    private LocalDateTime updateTime;
} 